/*
 * Copyright (C) 2009 nukin. CHINA.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */
 
#include <ZApplication.h>
#include "FileManage.h"
#include "login.h"
#include <qhbox.h>
#include <qvbox.h>
#include <qlineedit.h>
#include <ezxutilpushbutton.h>
#include <qdir.h>

LoginWidget::LoginWidget( QWidget* parent,  const char* name, int modal, WFlags fl)
	: ZBaseDialog(parent, name, modal, fl)
{
	
	//setWFlags(Qt::WType_Modal|WStyle_StaysOnTop);
	
	QVBoxLayout *vbl = new QVBoxLayout ( this, 0, 0 );
	setGeometry(10, 50, 216, 22 );
	QVBox *vb = new QVBox (this);
	vb->setMargin( 4 );
	QLabel *lb = new QLabel ( QString::fromUtf8("请输入密码:"),vb );
	lb->setFixedHeight( lb->height() + 4 );
			
	edtPassword = new QLineEdit( vb );
	edtPassword->setEchoMode( QLineEdit::Password );
		
	vbl->addWidget( vb );

	QHBox *hb = new QHBox(this );
	hb->setMargin( 0 );
	hb->setSpacing( 0 );

	ZPushButton *okBtn = new ZPushButton(hb, 0, -1, -1);
	okBtn->setText(QString::fromUtf8("确定"));	
	connect( okBtn, SIGNAL( clicked() ), this, SLOT( returned() ) );
	
	ZPushButton *cancelBtn = new ZPushButton(hb, 0, -1, -1);
	cancelBtn->setText(QString::fromUtf8("取消"));	
	connect( cancelBtn, SIGNAL( clicked() ), this, SLOT( reject() ) );
	
	vbl->addWidget( hb );


	
}

LoginWidget::~LoginWidget()
{
	
}


void LoginWidget::returned()
{
	// check userid and password
	QString loginUserPW;
	//Config cfg (QDir::currentDirPath()+"/xptools.conf" );
	SETUP_SET_Manager mgr("FileManage.ini", false);
	mgr.getSettingInfo("Login","password",loginUserPW,"1010",false);
	if(edtPassword->text()==loginUserPW) 
	{
		FileManage *fmg = new FileManage;
		fmg->exec();
		accept();
		delete this;
		
	}
	else
	{
		RES_ICON_Reader ir;
		ZMessageBox::timerInformation(this,ir.getIcon(RES_ICON_DLG_ERROR,true),QString::fromUtf8("密码错误！"),1);
	}
		
}

